<template>
<div class="container">
      <div class="container_top">
          <h2 class="container_top_text">代码仓库&nbsp({{warehouselist.length>0?warehouselist.length:0}})</h2>
          <el-popover placement="bottom" trigger="hover">
					<div class="popover-content-bottom">
						<span class="popover-content-top-title" @click="addwarehouseclick">新建仓库</span>
						<span class="popover-content-top-title" @click='relation'>关联仓库</span>
					</div>
					<el-button slot="reference" size="medium" type="primary" icon='el-icon-plus'>新建</el-button>
				</el-popover>
      </div>
      <div class="container_top_heard">
          <div class="container_top_heard_left">
                <selectRoleTwo title='负责人' selectType='singleChoice' ref="personselectempty" @selectsuccess="personsuccess"></selectRoleTwo>
              <!-- <el-dropdown trigger="click" class="container_top_heard_left_dropdown" @command="handleCommand" @blur="handleCommandblur" @focus="handleCommandfocus">
                <span class="el-dropdown-link">
                  {{dropdowntitle}} <i class="iconfont icon-xia" :class="[group==true?'select-header-icon':'select-header-iconTwo']"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="待开始" class="dropdownslect" style="font-size:16px;margin-top:10px">待开始</el-dropdown-item>
                  <el-dropdown-item command="进行中" class="dropdownslect"  style="font-size:16px;">进行中</el-dropdown-item>
                  <el-dropdown-item command="已关闭" class="dropdownslect"  style="font-size:16px;">已关闭</el-dropdown-item>
                  <el-dropdown-item command="已逾期" class="dropdownslect"  style="font-size:16px;">已逾期</el-dropdown-item>
                  <el-dropdown-item command="取消选择" divided class="dropdownslect"  style="font-size:16px;border-top: solid 1px #cccccc;">取消选择</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown> -->
                <div class="container_top_heard_input">
                    <el-input size="small"  placeholder="请输入里程碑关键字" prefix-icon="el-icon-search" @keyup.enter.native="keyupenter" v-model="queryInput"> </el-input>
                    <span class="container_top_heard_span" @click="empty">清空</span>
                </div>
          </div>
        <!-- <div class="container_top_heard_right">
              <div style="width:45px">
              <el-dropdown trigger="click" @command="handleCommandTime"  style="margin-right:10px;">
                  <span class="el-dropdown-link_Time">
                    <i class="el-icon-sort app_search"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item :class="[sortType=='Default'?'dropdownslectTWo':'dropdown']"  command="Default"><i v-if="sortType=='Default'" class="el-icon-check"></i>默认排序</el-dropdown-item>
                    <el-dropdown-item :class="[sortType=='CreationTime'?'dropdownslectTWo':'dropdown']"   command="CreationTime"><i v-if="sortType=='CreationTime'" class="el-icon-check"></i>创建时间</el-dropdown-item>
                    <el-dropdown-item :class="[sortType=='Updatetime'?'dropdownslectTWo':'dropdown']"   command="Updatetime"><i v-if="sortType=='Updatetime'" class="el-icon-check"></i>更新时间</el-dropdown-item>
                  </el-dropdown-menu>
              </el-dropdown>
              </div>
        </div> -->

      </div>
      <div class="container-center">
      <div class="app_item" v-for="item in warehouselist">
        <div class="app_item_mian">
            <div class="app_item_mian_top">
                <el-dropdown trigger="click">
                  <span><i class="el-icon-arrow-down el-icon-s-unfold"></i></span>
                   <el-dropdown-menu slot="dropdown">
                      <div class="container_top_heard_right_checkbox">
                        <span @click="editwarehouseclick(item)">修改</span>
                        <!-- <span>置顶</span> -->
                        <span @click='delwarehouse(item)'>删除</span>
                      </div>
                    </el-dropdown-menu>
                 </el-dropdown>
                <div class="app_item_mian_top_span">{{item.name}}</div>
            </div>
            <div style="font-size:14px;margin-top:8px;color: #1890ff">
              <a :href="item.gitUrl" target="_blank">点击跳转</a>
            </div>
        </div>
            <div class="app_item_stats">{{item.createTime}}</div>
      </div>
       <div class="projectTask_data"  v-if="warehouselist.length<1" v-cloak>
		   <el-empty description="暂无仓库"></el-empty>
	    </div>
      </div>
      <div class="proj_pagination">
				<pagination v-show="total>0" :total="total" :current.sync="current" :size.sync="size" @pagination="listclic"/>
			</div>
          <el-dialog title="关联代码仓库" :visible.sync="dialogVisible" width="30%" :close-on-click-modal='false'>
        <div class="member_add_div">请选择代码仓库</div>
         <el-select v-model="gitId"  size="medium" placeholder="请选择仓库" clearable style="display:block;margin-top:20px;width:100%">
          <el-option v-for="item in gitoption" :key="item.value" :label="item.name" :value="item.gitId">
         </el-option>
        </el-select>
          <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="projGitsaveclick">确 定</el-button>
        </span>
    </el-dialog>
      </div>
</template>
<script>
import pagination from "@/components/Pagination/index.vue";
import { EventBus } from '@/api/eventbus'
import { list, del, projGitsave,projGitdelect} from "@/api/git";
import selectRoleTwo from "@/components/screen/selectRoleTwo";
import milepost from "@/components/projectComponents/milepost";
export default {
  components: {
    selectRoleTwo,
    milepost,
    pagination
  },
  data() {
    return {
      activeName: "second",
      dropdowntitle: "内源",
      group: true,
      queryInput: "",
      sortType: "Default",
      warehouselist: [],
      current: 1,
      size: 10,
      total: 0,
      dialogVisible: false,
      masterUserId: "",
      gitoption: [],
      gitId: "",
    };
  },
  created() {
    this.listclic();
    // console.log(EventBus.$on('git-add'));
      EventBus.$on('git-add', res => { // 监听新增完毕
                // 更新列表数组
                console.log('45485645634564654654531');
          this.warehouselist.splice(0, 0, res)
      });
  },
  mounted() {

    let that = this;
    //点击页面空白处隐藏下拉列表
    document.addEventListener("click", function () {
      that.isShow = false;
    });
  },
  methods: {
    projGitsaveclick() {
      projGitsave({projId:this.$route.query.id,gitId:this.gitId}).then((res) => {
        this.dialogVisible=false
        this.warehouselist.splice(0, 0, res.data)
      });
    },
    gitoptionlistclic() {
      let params = new URLSearchParams();
      params.append("current", this.current);
      params.append("size", this.size);
      list(params).then((res) => {
        this.gitoption = res.data.records;
      });
    },
    delwarehouse(data) {
      let _this = this;
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let parmat = new URLSearchParams();
          parmat.append("projId", this.$route.query.id);
          parmat.append("gitId", data.gitId);
          projGitdelect(parmat).then((ress) => {
            _this.warehouselist.forEach(function (item, index) {
              if (item.gitId == data.gitId) {
                _this.warehouselist.splice(index, 1);
              }
            });
            this.$message({ message: "删除成功", type: "success" });
          });
        })
        .catch(() => {});
    },
    relation() {
      this.dialogVisible = true;
      this.gitoptionlistclic();
    },
    listclic() {
      let params = new URLSearchParams();
      params.append("current", this.current);
      params.append("size", this.size);
      params.append("projId", this.$route.query.id);
      params.append("masterUserId", this.masterUserId);
      params.append("name", this.queryInput);
      list(params).then((res) => {
        this.warehouselist = res.data.records;
        this.total = res.data.total;
      });
    },
    currentChange() {},
    editwarehouseclick(data) {
      this.$router.push({
        path: "/git/gitedit",
        query: { gitId: data.gitId },
      });
    },
    addwarehouseclick() {
      this.$router.push({
        path: "/git/gitAdd",
        query: { id: this.$route.query.id },
      });
    },
    empty() {
      this.$refs.personselectempty.emptyclick();
      this.queryInput=''
      this.masterUserId=''
      this.listclic()
    },
    keyupenter(e){
       var keyCode = window.event? e.keyCode:e.which;
      if(keyCode == 13){
          this.name=e.target.value
          this.listclic()
      }},
    personsuccess(data) {
      if(data.length>0){this.masterUserId = data[0].userId;}
      else{this.masterUserId=""}
      this.listclic();
    },
    handleCommandTime(item) {
      this.sortType = item;
    },
    handleCommandblur() {
      this.group = true;
    },
    handleCommandfocus() {
      this.group = false;
    },
    handleCommand(data) {
      console.log(data);
      this.group = false;
      if (data == "取消选择") {
        this.dropdowntitle = "状态";
      } else {
        this.dropdowntitle = data;
      }
    },
  },
};
</script>
 <style scoped>
.container_top {
  display: flex;
  justify-content: space-between;
}
.container_top_text {
  margin: 0;
}
.ge_content_right_button {
  color: #ffffff;
}
.container_top_heard {
  margin-top: 8px;
  width: 100%;
  height: 40px;
  background-color: rgb(245, 246, 248);
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 8px;
  justify-content: space-between;
}
.container_top_heard_left {
  display: flex;
  align-items: center;
}
.container_top_heard_left_dropdown {
  width: 88px;
  display: flex;
  justify-content: center;
  cursor: pointer;
}
.el-dropdown-link {
  /* border: 1px solid blanchedalmond; */
  /* width: 88px; */
  font-size: 14px;
  font-weight: 500;
  color: rgb(46, 64, 94);
}
.el-dropdown-link:focus {
  /* width: 93px;   */
  display: block;
  box-sizing: border-box;
  font-size: 14px;
  font-weight: 700;
  color: rgb(46, 64, 94);
  padding: 8px;
  border-radius: 10px;
  border: 3px solid #167ef8;
}
.el-dropdown-link_Time {
  height: 35px;
  font-size: 14px;
  font-weight: 700;
  color: rgb(46, 64, 94);
  padding: 8px;
}
.el-dropdown-link_Time:focus {
  height: 38px;
  display: block;
  padding: 8px;
  box-sizing: border-box;
  font-size: 14px;
  color: rgb(46, 64, 94);
  border-radius: 10px;
  border: 3px solid #167ef8;
}
.dropdownslect {
  cursor: pointer;
  display: block;
  height: auto;
  text-align: left;
  border: none;
  color: #2e405e;
  padding: 0.71428571rem 1.14285714rem !important;
  font-size: 14px;
  text-transform: none;
  font-weight: 400;
  box-shadow: none;
  line-height: 24px;
  /* background-color: #e8f4ff; */
  /* color: #46a6ff; */
}
.dropdownslectTWo {
  cursor: pointer;
  display: block;
  height: auto;
  text-align: left;
  border: none;
  color: #2e405e;
  padding: 0.71428571rem 1.14285714rem !important;
  font-size: 14px;
  text-transform: none;
  font-weight: 400;
  box-shadow: none;
  line-height: 24px;
  background-color: #e8f4ff;
  color: #46a6ff;
}
.dropdown {
  cursor: pointer;
  display: block;
  height: auto;
  text-align: left;
  border: none;
  color: #2e405e;
  padding: 0.71428571rem 1.14285714rem !important;
  font-size: 14px;
  text-transform: none;
  font-weight: 400;
  box-shadow: none;
  line-height: 24px;
}
.select-header-icon {
  font-size: 12px;
  color: #333333;
  margin-right: 4px;
  transition: all 0.5s;
  transform: rotate(-180deg);
}

.select-header-iconTwo {
  font-size: 12px;
  color: #333333;
  margin-right: 4px;
  transition: all 0.5s;
}
.container_top_heard_input {
  margin-left: 8px;
  display: flex;
  align-items: center;
}
.container_top_heard_span {
  width: 50px;
  font-size: 14px;
  color: rgb(144, 154, 170);
  margin-left: 10px;
  /* line-height: 20px; */
  cursor: pointer;
}
.container_top_heard_right {
  display: flex;
  align-items: center;
}
.container_top_heard_right_checkbox {
  padding: 10px;
}
.el-checkbox-group .el-checkbox {
  display: block;
  display: flex;
  align-items: center;
  font-size: 18px;
  margin-top: 5px;
}
.container_top_heard_right_checkbox_cencal {
  font-size: 14px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: solid 1px #cccccc;
  cursor: pointer;
  color: rgb(46, 64, 94);
}

.app_item_seting {
  padding-top: 5px;
}
.app_item_statssrtting {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
.app_item_seting {
  display: flex;
  align-items: flex-start;
  margin-bottom: 8px;
  margin-left: 10px;
}
.app_item {
  display: flex;
  box-shadow: rgb(236, 237, 240) 0px -1px 0px 0px inset;
  padding: 8px;
}
.app_item_mian {
  flex: 6;
  padding: 14px 0px;
  /* background-color: aquamarine; */
}
.app_item_stats {
  flex: 4;
  padding: 14px 0px;
  font-size: 13px;
  color: rgb(46, 64, 94);
  display: flex;
  justify-content: end;
}
.app_item_mian_top {
  display: flex;
  align-items: center;
}
.app_item_mian_top_span {
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
  word-break: break-word;
  color: rgb(46, 64, 94);
  margin-left: 20px;
}

.app_item_mian_bottom {
}
.app_item_mian_bottom_span {
  font-size: 13px;
  color: rgb(46, 64, 94);
}
.app_item_mian_bottom_span_one {
  font-size: 12px;
  color: rgb(144, 154, 170);
  margin-left: 8px;
}
.cpnter_app {
  width: 100%;
  height: 24px;
}
.app_item_seting {
  cursor: pointer;
}
.container_top_heard_right_checkbox span {
  display: block;
  /* width:100px; */
  cursor: pointer;
  padding: 10px;
  text-align: center;
}
.container_top_heard_right_checkbox span:hover {
  display: block;
  /* width:100px; */
  cursor: pointer;
  padding: 10px;
  text-align: center;
  background-color: #f5f6f8;
}
.el-icon-s-unfold {
  font-size: 15px;
  cursor: pointer;
}
.bottom {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.projectTask_data {
  width: 100%;
  display: flex;
  justify-content: center;
  color: #909aaa;
      align-items: center;
}
.popover-content-top-title {
  color: #2e405e;
  font-size: 14px;
  display: block;
  width: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
  padding-right: 10px;
}

.popover-content-top-title:hover {
  background-color: #f5f6f8;
  color: #2e405e;
  font-size: 14px;
  display: block;
  width: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
  padding-right: 10px;
}
.member_add_div {
  font-size: 13px;
  font-weight: 700;
  color: rgb(46, 64, 94);
  margin-bottom: 10px;
}
[v-cloak] {
  display: none !important;
}
.proj_pagination {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 64px;
}
</style>
